import {createRouter, createWebHistory,createWebHashHistory } from 'vue-router'

const modules = import.meta.glob("../views/**/**.vue");

const children: any = [];
const routes = [
    {
        path: '/',
        name: 'login',
        component: () => import('../views/LoginView.vue'),
    }, {
        path: '/main',
        name: 'layout',
        component: () => import('../views/LayoutView.vue'),
        redirect: '/home',
        children: children
    },
]

const userInfo = JSON.parse(localStorage.getItem("userInfo"));
if (userInfo !== null) {
    for (let i = 0; i < userInfo.menuList.length; i++) {
        const item = userInfo.menuList[i];
        const menuItem = {
            path: item.m_path,
            name: item.m_id,
            component: modules[`../views/pages/${item.m_component}View.vue`],
        };
        children.push(menuItem);
    }
}

const router = createRouter({
    history: createWebHashHistory(import.meta.env.BASE_URL),
    routes,
})

export default router

